package com.lijianlove.keeplearning.dr.test;

import com.lijianlove.keeplearning.dr.support.annotation.DR;
import com.lijianlove.keeplearning.entity.User;
import com.lijianlove.keeplearning.strategy.UserStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Random;

/**
 * @author lijian
 * @date 2019/4/30 下午5:04
 */
@Slf4j
@Service
public class DRService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private UserStrategy userStrategy;

    /**
     * 10s 后过期
     *
     * @param user
     */
    @Transactional
    @DR(calBit = 2, expire = 10 * 1000)
    public void testdr(User user) {
        log.info("testdr start");
        Random random = userStrategy.saveToDb1(jdbcTemplate);
//        int i = 1 / 0;
        userStrategy.saveToDb2(random, jdbcTemplate);
        log.info("testdr end");
    }
}
